import { rootPath } from './apps/path.js'
import * as path from 'path'
import * as fs from 'fs'
import colors from 'colors-console';

const COPYRIGHT_PATTERN = 'copyright: `Created By ${Ver';
const REPLACEMENT = 'copyright: `Created By MurasamePro & ${Ver';

if (!global.segment)
  global.segment = (await import('oicq')).segment

if (!segment.button)
  segment.button = () => ""

export * from './apps/index.js'

if (fs.existsSync(path.join(rootPath, 'plugins', 'miao-plugin'))) {
  let miaopath = path.join(rootPath, 'plugins', 'miao-plugin')
  const filePath = path.join(miaopath, 'components', 'common', 'Render.js');
  const content = fs.readFileSync(filePath, 'utf8');
  if (content.includes(COPYRIGHT_PATTERN)) {
    logger.info('---------^_^---------')
    logger.info(colors('green', `丛雨原插件初始化~`))
    const newContent = content.replace(
      COPYRIGHT_PATTERN,
      REPLACEMENT
    );
    fs.writeFileSync(filePath, newContent, 'utf8');//版权注释修改

    logger.info(colors('green', `丛雨原插件初始化成功~`))
  }
}
if (fs.existsSync(path.join(rootPath, 'plugins', 'miao-plugin'))) {
  await renamehelpmiao();
  logger.info('------------QAQ------------')
  logger.info(colors('green', 'Murasame-genshin loaded successfully'))
  logger.info(colors('green', '丛雨原插件载入成功'))
  logger.info('---------------------------')
} else {
  logger.info(colors('red', '检测到你未安装miao-plugin插件，请务必先安装miao-plugin，本插件是基于喵喵原神的拓展'))
}
async function renamehelpmiao() {
  if (fs.existsSync(path.join(rootPath, 'plugins', 'miao-plugin'))) {
    let miaopath = path.join(rootPath, 'plugins', 'miao-plugin')
    const filePath = path.join(miaopath, 'config', 'help.js');
    if (fs.existsSync(filePath)) {
      const content = fs.readFileSync(filePath, 'utf8');
      if (content.includes('subTitle: \'Yunzai-Bot')) {
        const newContent1 = content.replace(
          'subTitle: \'Yunzai-Bot',
          'subTitle: \'MurasamePro & Yunzai-Bot'
        );
        const newContent = newContent1.replace(
          'title: \'喵喵帮助\'',
          'title: \'喵喵-丛雨原Pro帮助\''
        )
        fs.writeFileSync(filePath, newContent, 'utf8');//帮助面板注入丛雨原标识
      }
    }
  }
}